package com.NeuglsWorkStudio.UI.CustomMenu
{
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;

	public class TCustomContextMenu
	{
		private static  var _FContextMenu:CustomContextMenu=null;
		
		/**
		 * 构建自定义的Flash鼠标右键**/
		public function TCustomContextMenu()
		{
		}
		
		
		private static function GetListener(F:Function):Function{
			return function(E:ContextMenuEvent):void{
				if(F!=null){
					F();
				}
			}	
		}
		
		/**
		 * 创建自己的Flash鼠标右键
		 * @param Items 鼠标右键数组，每一项都是TCustomContextMenuItem对象**/
		public static function BuildMyOwnContextMenu(Items:Array):ContextMenu{
			if(!_FContextMenu){
				_FContextMenu=new CustomContextMenu(true,null);
			}
			
			for(var I:int=0;I<Items.length;I++) 
			{ 
				var MenuItem:TCustomContextMenuItem=Items[I] as TCustomContextMenuItem;
				_FContextMenu.addCustom(
					GetListener(MenuItem.OnClick),MenuItem.Caption,MenuItem.SeparatorBefore,
					MenuItem.Enabled,MenuItem.Visible);
			}
			
			return _FContextMenu.contextMenu;
		} 
	}
}